<template>
  <Container class="storeresign-list">
    <HeadFormItem
      slot="header"
      :list="list"
      :pay-type-list="payTypeList"
      @onSearchBtnClick="onSearchBtnClick"
    />
    <Tabs v-model="tab">
      <export-btn 
        :param="exportParam" 
        url='/distributor/purch_order/payment/export'
        class="item" 
        slot="extra"></export-btn>
      <TabPane label="订单收款单" name="tab1">
        <homeTable
          :list="list"
          @getData="getData"
          @onPageSizeChange="onPageSizeChange"
          @onPageChange="onPageChange"
        />
      </TabPane>
    </Tabs>
  </Container>
</template>
<script>
import ListData from './list/ListData'
import HeadFormItem from './list/HeadFormItem'
import homeTable from '@/components/homeTable'

import { clearEmpty } from '@/util'
export default {
  name: 'report/receipt/receiptList',
  components: {
    HeadFormItem,
    homeTable
  },
  data () {
    return {
      tab: 'tab1',
      list: ListData,
      payTypeList: []

    }
  },
  watch: {
  },
  mounted () {
    this.list.currentPage = ~~this.$route.query.currentPage || 1
    this.list.pageSize = ~~this.$route.query.pageSize || this.list.pageSize
    this.getData()
    this.getPayType()
  },
  destroyed () {
    this.$bus.$off()
  },
  methods: {
    onSearchBtnClick () {
      this.list.currentPage = 1
      this.getData()
    },
    add () {
      this.$refs.BarCodeModel.openModal()
    },
    detailInfo (row) {
      this.$refs.BarCodeDetailModel.openModal(row)
    },
    getPayType () {
      this.$ajaxGet('/distributor/purch_order/payment/payType').then(data => {
        this.payTypeList = data.filter(item => item.channel != 1)
      })
    },
    getData () {
      this.list.status = 'loading'
      let param = {
        current: this.list.currentPage,
        size: this.list.pageSize,
        ...this.list.form
      }
      if (this.list.form.payType) {
        param.payTypeList = [this.list.form.payType]
      }
      delete param.payType
      delete param.payType
      param = clearEmpty(param)
      this.$jsonPost('/distributor/purch_order/payment/page', param).then(data => {
        this.list.data = []
        this.list.totalItem = Number(data.total)
        this.list.data = (data.records || [])
        this.list.status = 'pass'
      })
        .catch(() => {
          this.list.status = 'error'
        })
    },
    onPageChange (number) {
      this.list.currentPage = number
      this.$router.push({
        query: {
          currentPage: this.list.currentPage,
          pageSize: this.list.pageSize
        }
      })
      this.getData()
    },
    onPageSizeChange (pageSize) {
      this.list.currentPage = 1
      this.list.pageSize = pageSize
      this.$router.push({
        query: {
          currentPage: this.list.currentPage,
          pageSize: this.list.pageSize
        }
      })
      this.getData()
    },
    onRefresh () {
      this.getData()
    }
  },
  computed: {
    exportParam() {
      let params = {
        current: this.list.currentPage,
        ...this.list.form
      }
      if (this.list.form.payType) {
        params.payTypeList = [this.list.form.payType]
      }
      delete params.payType
      params = clearEmpty(params)
      return params
    }
  }
}
</script>
